﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BiffenService.Control;
using BiffenService.Model;
using System.Data.SqlClient;
using System.ServiceModel;
using BiffenService.Db;
using BiffenService.Db.Exceptions;

namespace BiffenService
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class BiffenService : IBiffenService
    {
        #region . Global .
        public bool IsItFriday()
        {
            return DateTime.Now.DayOfWeek == DayOfWeek.Friday;
        }
        #endregion

        #region . PriceCategory .
        public List<PriceCategory> GetAllPriceCategories()
        {
            return PriceCategoryControl.GetAllPriceCategories();
        }

        public PriceCategory GetPriceCategory(int id)
        {
            return PriceCategoryControl.GetPriceCategory(id);
        }

        #endregion

        #region . Movie .
        public Movie GetMovie(int id)
        {
            return MovieControl.GetMovie(id);
        }

        public List<Movie> GetAllMovies()
        {
            return MovieControl.GetAllMovies();

        }

        public int AddMovie(Movie m)
        {
            return MovieControl.AddMovie(m);
        }

        public int EditMovie(Movie m)
        {
            return MovieControl.EditMovie(m);
        }

        public int DeleteMovie(int id)
        {
            return MovieControl.DeleteMovie(id);
        }

        public List<Movie> GetCurrentMovies()
        {
            return MovieControl.GetCurrentMovies();
        }

        public List<Movie> SearchMovies(ICollection<string> searchParams, string queryString)
        {
            try
            {
                return MovieControl.SearchMovies(searchParams, queryString);
            }
            catch (IllegalParameterException e)
            {
                throw new FaultException<IllegalParameterFault>(new IllegalParameterFault());
            }
            catch (EmptyParameterException e)
            {
                throw new FaultException<EmptyParameterFault>(new EmptyParameterFault());
            }
        }

        #endregion

        #region . Show .
        public List<Booking> GetBookingsForShow(Show show)
        {
            return new BookingControl().GetBookingsForShow(show);
        }

        public List<Show> GetShowsForMovie(int id)
        {
            return ShowControl.GetShowsForMovie(id);
        }

        public List<Show> GetCurrentShowsSeven(DateTime date, int theaterId)
        {
            return ShowControl.GetCurrentShowsSeven(date, theaterId);
        }

        public bool AddShow(Show show)
        {
            return ShowControl.AddShow(show);
        }

        public bool DeleteShow(Show show)
        {
            return ShowControl.DeleteShow(show);
        }
        #endregion

        #region . Booking .
        public List<Booking> FindBookingByPhone(int phone)
        {
            return BookingControl.FindBookingByPhone(phone);
        }

        public Booking FindBookingById(int bookingId)
        {
            return BookingControl.FindBookingById(bookingId);
        }

        public int DeleteBookingById(int bookingId)
        {
            return BookingControl.DeleteBookingById(bookingId);
        }

        public int CreateBooking(int Status, int PhoneNumber, int DiscountType, int ShowId, List<int> Seats, int MemberId)
        {
            try
            {
                return BookingControl.CreateBooking(Status, PhoneNumber, DiscountType, ShowId, Seats, MemberId);
            }
            catch (SeatAlreadyReservedException)
            {
                throw new FaultException<SeatsAlreadyReservedFault>(new SeatsAlreadyReservedFault());
            }
            
        }

        public int MarkBookingAsSold(int id)
        {
            return BookingControl.MarkBookingAsSold(id);
        }
        #endregion


        #region . Login .

        public Login GetLoginByPhone(int phone)
        {
            return MemberControl.GetLoginByPhone(phone);
        }

        #endregion

        #region . Member .

        public Member FindMemberById(int memberId)
        {
            return MemberControl.FindMemberById(memberId);
        }

        public Member FindMemberByPhone(int phone)
        {
            return MemberControl.FindMemberByPhone(phone);
        }

        public int InsertMemberIntoDatabase(string name, int phone, string email, string Address, int zipcode, bool newsletter)
        {
            return MemberControl.CreateMember(name, phone, email, Address, zipcode, newsletter);
        }

        #endregion




    }
}